KISSY.use("node",function(S,Node){ 
function show_tip(select){
	var target = $('.'+select);
	var shell = KISSY.UA.shell;
	var topadd=-220;
	// switch(shell){
		// case "firefox" :
		// topadd=-220;
		// break;
	// }
	for (var i=0;i<target.lenth;i++){
		target.item(i).attr("data-tipc",i);
		var top = target.item(i).offset().top+topadd;
		var left = target.item(i).offset().left;
		var info = target.item(i).attr("data-tip");
		if(info=="show"){
			var show = target.item(i).attr("data-tip-info");
			$("."+show).addClass(select+i+'-tip');
			KISSY.DOM.css('.'+show, "top",top+"px");
			KISSY.DOM.css('.'+show, "left",left+"px");
		}else{
			var temp = '';
			temp+='<div class="'+select+i+'-tip bui-overlay bui-ext-position tips tips-small tips-info tips-no-icon hide" style="top:'+top+'px; left:'+left+'px;">';
			temp+='<div class="tips-content">'+info+'</div>';
			temp+='</div>';
			$(temp).insertAfter(target.item(i));
		}
		target.item(i).on("mouseenter mouseleave",function(){
			var c = $(this).attr("data-tipc");
			$('.'+select+(c)+"-tip").toggleClass("hide");
		});	
	}
}
show_tip("helper");
var DOM = KISSY.DOM;
var start = DOM.get('.start-calendar');
var end = DOM.get('.end-calendar');
var sign = DOM.get('.signday-calendar');
TimeSet(start,1);
TimeSet(end,2);
TimeSet(sign,0,'max');
$(".js-useditor").on("click",function(){
	showDialog("使用高级编辑器","<div class=\"centered \">请在打开的窗口中编辑内容，完成后点击<button class=\"button read\" type=\"button\">读取</button></div>","form-horizontal");
	$(".cancel").remove();
	var content = $(".content").val();
	$(".read").on("click",function(){
		KISSY.io({
			url: "/?a=readeditor&m=shop&c=event",
			success: function(data, textStatus) {
				$(".content").val(data.content);
				closeDialog();
				showDialog("注意","已读取编辑器设置的详情代码，请不要直接修改这些代码，如需修改，请再次点击“使用高级编辑器”。","form-horizontal");
			},
			error: function(){
				alert('error');
			},
			dataType:"jsonp"
		});
	});
});
$("form").on("submit",function(){

	var start_time = $(".start-calendar").val();
	if(!CheckDate(start_time)){alert("请用日历选择开始时间！");return false;}
	var tomorrow =GetDateStr(1);
	if(!isStartEndDate(tomorrow,start_time)){
		alert("开始日期必须在24小时之后"); return false;
	}
	var end_time = $(".end-calendar").val();
	if(!CheckDate(end_time)){alert("请用日历选择结束时间！");return false;}
	if(!isStartEndDate(start_time,end_time)){
		alert("开始日期不能大于结束日期"); return false;
	}
// alert(KISSY.DOM.get(".ks-editor").innerHTML);
	// var params = $(".form");
	// var l=(params.len());
	// var str=new Array();
	// for(var i=0;i<l;i++){
		// // if(params.item(i).attr("data-post")=="content"){
		// // if(1==1){
			// // str.push('"'+params.item(i).attr("data-post")+'":"'+params.item(i).val()+'"');
		// // }else{
			// var node = params.item(i).getDOMNode();
			// if(node.type=="checkbox"){
				// str.push('"'+params.item(i).attr("data-post")+'":"'+node.checked+'"');
			// }else{
				// var s = params.item(i).attr("data-post");alert(s);
				// if (s=="start_time"){
					// var start_time = params.item(i).val();alert(start_time);
					// if(!CheckDate(start_time)){alert("请用日历选择日期！");return false;}
					// var tomorrow =GetDateStr(1);
					// if(!isStartEndDate(start_time,tomorrow)){
						// alert("开始日期必须在24小时之后"); return false;
					// }
				// }
				// if (s=="end_time"){
					// var end_time = params.item(i).val();
					// if(!CheckDate(end_time)){alert("请用日历选择日期！");return false;}
				// }
				// if(!isStartEndDate(start_time,end_time)){
					// alert("开始日期不能大于结束日期"); return false;
				// }
				// str.push('"'+params.item(i).attr("data-post")+'":"'+params.item(i).val()+'"');
				
			// }
		// // }
	// }
	// var	tmp="<span>{"+str.join(",")+"}</span>";
	// $(tmp).appendTo(".res");
	return true;
});
function GetDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m = dd.getMonth()+1;//获取当前月份的日期
	if(m<10){m="0"+m;}
    var d = dd.getDate();
	if(d<10){d="0"+d;}
    var H = dd.getHours();
    var i = dd.getMinutes();
    var s = dd.getSeconds();
    return y+"-"+m+"-"+d+" "+H+":"+i+":"+s;
}
function CheckDate(strDate){   
	if(strDate.length>0){   
		var reg= /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;  
		return (reg.test(strDate));  
	}else{   
		return false;   
	}
}
function isStartEndDate(startTime,endTime){            
	if(startTime.length>0 && endTime.length>0){  
		var st = startTime.split(" ");  
		var et = endTime.split(" ");  
		var startTmp=st[0].split("-");  
		var endTmp=et[0].split("-");  
		var sd=new Date(startTmp[0],startTmp[1],startTmp[2]);
		var ed=new Date(endTmp[0],endTmp[1],endTmp[2]);
		if(sd.getTime()>ed.getTime()){    
			return false;     
		}     
	}     
	return true; 
}      

$(".pre_step").on("click",function(){
	location.href=("/?a=event_step1&m=shop&c=event");
});
// GS.addListener('cajaupload',function(d){
		// var response = KISSY.JSON.parse(d.content);
		// // var info = KISSY.DOM.get(".fileInfo");
		// // var img = KISSY.DOM.get('.uImage',info);
		// // var st = KISSY.DOM.get(".fileStatus", info);
		// // //var name = KISSY.DOM.get(".fileName", info);
		// // // var ID = KISSY.DOM.get(".fileId", info);
		// // // var size = KISSY.DOM.get(".fileSize", info);
		// // var url = KISSY.DOM.get(".imgurl", info);
		
		// if(response['success']){
			// // st.innerHTML = "成功";
			// // img.innerHTML = '<a href="'+response['url']+'"><img src="'+response['url']+'" width="64" /></a>';
			// // // name.innerHTML = response['name'];
			// // // ID.innerHTML = response['id'];
			// // // size.innerHTML = response['size'];
			// // url.value = response['url'];
			// $(".imgurl").val(response['url']);
			// $(".upImage").empty();
			// var str = "<img src='"+response['url']+"_120x120.jpg' />";
			// $(str).appendTo(".upImage");
		// }else{
			// st.innerHTML = "失败";
			// img.innerHTML = "";
			// // name.innerHTML = "";
			// // ID.innerHTML = "";
			// // size.innerHTML = "";
			// url.innerHTML = "";
		// }
	// });
for(var i=6;i>=0;i--){
	$(".lev"+i).on("click",function(){
		var lev = $(this).attr("data-lev");
		for(var i=6;i>=0;i--){
		KISSY.DOM.query(".lev"+i)[0].checked=false;
		}
		for(var i=6;i>=lev;i--){
			KISSY.DOM.query(".lev"+i)[0].checked=true;
		}
	});
}
var l=($(".xcount").length);
for(var i=0;i<l;i++){
$(".xcount").item(i).on("blur",function(){
	var chk = $(this).attr("data-chk");
	if($(this).val()==""||$(this).val()==0){
		KISSY.DOM.query(".chk"+chk)[0].checked=false;
	}else{
		KISSY.DOM.query(".chk"+chk)[0].checked=true;
	}
});

}
$('.areabtn').on("click",function(){
	if(KISSY.DOM.query(".areachk")[0].checked==true){
		KISSY.DOM.query(".areachk")[0].checked=false;
		KISSY.DOM.css('.arease', "visibility","hidden");
		KISSY.DOM.css('.arease', "height","0");
	}else{
		KISSY.DOM.query(".areachk")[0].checked=true;
		KISSY.DOM.css('.arease', "visibility","visible");
		KISSY.DOM.css('.arease', "height","auto");
	}
});

$('.blselect').on("change",function(){
	$(".buyerlev").empty();
	if(this.value>4){
		var str = '<img src="'+GetCreditString(this.value)+'" />';
		// $(".buyerlev").innerHtml=(str);
		$(str).appendTo(".buyerlev");
	}
});
$(".aid0").on("click",function(){
	$('.bui-list-item').removeClass('bui-list-item-selected');
});
$('.bui-list-item').on("click",function(){
	$(".aid0").removeClass('bui-list-item-selected');
	$(this).toggleClass('bui-list-item-selected');
	var areas = new Array();
	var selected = $('.bui-list-item-selected');
	for(var i=0;i<selected.len();i++){
		areas.push(selected.item(i).attr('data-areaid'));
	}
	$('.areainput').val(areas.join(","));
	if(!$(".bui-list-item").hasClass('bui-list-item-selected')){
		$(".aid0").addClass('bui-list-item-selected');
	}
});
function GetCreditString($lev){
		if ($lev>4&&$lev<=10){
		$lev='http://pics.taobaocdn.com/newrank/b_red_1.gif';
		}else if($lev>10&&$lev<=40){
		$lev='http://pics.taobaocdn.com/newrank/b_red_2.gif';
		}else if($lev>40&&$lev<=90){
		$lev='http://pics.taobaocdn.com/newrank/b_red_3.gif';
		}else if($lev>90&&$lev<=150){
		$lev='http://pics.taobaocdn.com/newrank/b_red_4.gif';
		}else if($lev>150&&$lev<=250){
		$lev='http://pics.taobaocdn.com/newrank/b_red_5.gif';
		}else if($lev>250&&$lev<=500){
		$lev='http://pics.taobaocdn.com/newrank/b_blue_1.gif';
		}else if($lev>500&&$lev<=1000){
		$lev='http://pics.taobaocdn.com/newrank/b_blue_2.gif';
		}else if($lev>1000&&$lev<=2000){
		$lev='http://pics.taobaocdn.com/newrank/b_blue_3.gif';
		}else if($lev>2000&&$lev<=5000){
		$lev='http://pics.taobaocdn.com/newrank/b_blue_4.gif';
		}else if($lev>5000&&$lev<=10000){
		$lev='http://pics.taobaocdn.com/newrank/b_blue_5.gif';
		}else if($lev>10000&&$lev<=20000){
		$lev='http://pics.taobaocdn.com/newrank/b_cap_1.gif';
		}else if($lev>20000&&$lev<=50000){
		$lev='http://pics.taobaocdn.com/newrank/b_cap_2.gif';
		}else if($lev>50000&&$lev<=100000){
		$lev='http://pics.taobaocdn.com/newrank/b_cap_3.gif';
		}else if($lev>100000&&$lev<=200000){
		$lev='http://pics.taobaocdn.com/newrank/b_cap_4.gif';
		}else if($lev>200000&&$lev<=500000){
		$lev='http://pics.taobaocdn.com/newrank/b_cap_5.gif';
		}else if($lev>500000&&$lev<=1000000){
		$lev='http://pics.taobaocdn.com/newrank/b_crown_1.gif';
		}else if($lev>1000000&&$lev<=2000000){
		$lev='http://pics.taobaocdn.com/newrank/b_crown_2.gif';
		}else if($lev>2000000&&$lev<=5000000){
		$lev='http://pics.taobaocdn.com/newrank/b_crown_3.gif';
		}else if($lev>5000000&&$lev<=10000000){
		$lev='http://pics.taobaocdn.com/newrank/b_crown_4.gif';
		}else if($lev>10000000){
		$lev='http://pics.taobaocdn.com/newrank/b_crown_5.gif';
		}
	return $lev;
}
function TimeSet(input,addday,limit){
	KISSY.use('calendar',function(S,Calendar){
    // use Calendar

		var Calendar = KISSY.Calendar;
		var date = new Date();
		var param;
		if(limit=='max'){
		param = {popup: true, maxDate: date.setDate(date.getDate()+addday),showTime:true};
		}else{
		param = {popup: true, minDate: date.setDate(date.getDate()+addday),showTime:true};
		}
		var cal = new Calendar(input,param);
		cal.on('timeSelect', function (e) {
			var selectDate = new Date(e.date);
			var m = selectDate.getMonth()+1;
			var d = selectDate.getDate();
			var h = selectDate.getHours();
			var i = selectDate.getMinutes();
			var s = selectDate.getSeconds();
			m = m<10?'0'+m:m;
			d = d<10?'0'+d:d;
			h = h<10?'0'+h:h;
			i = i<10?'0'+i:i;
			s = s<10?'0'+s:s;
			
			var t = selectDate.getFullYear() + "-" + m + "-" + d +" "+h+":"+i+":"+s;
			input.value = t;
			cal.hide();
		});
	});
}

$(".repick").on("click",function(){
	location.href=("/?a=gamecfg&m=shopadmin&repick=1");
});
});